package com.lhy.admin.util;

/**
 * FileUtil
 *
 * @author hyluan
 * @date 2022年07月27日 16:41
 */
public class FileUtil {
    /**
     * getType 根据文件名虎丘文件类型
     *
     * @param fileName fileName
     * @return {@link String}
     * @author hyluan
     * @date 2022/7/27 16:41
     */
    public static String getType(String fileName) {
        if (fileName == null) {
            return "";
        }
        String[] split = fileName.split("\\.");
        String fileType = "";
        if (split.length > 1) {
            fileType = split[split.length - 1];
        } else {
            fileType = fileName;
        }
        return fileType;
    }

    /**
     * geSuffix 根据文件名虎丘文件名前缀
     *
     * @param fileName fileName
     * @return {@link String}
     * @author hyluan
     * @date 2022/7/27 16:41
     */
    public static String geSuffix(String fileName) {
        String[] split = fileName.split("\\.");
        StringBuilder fileNamePix = new StringBuilder();
        if (split.length > 1) {
            for (int i = 0; i < split.length - 1; i++) {
                fileNamePix.append(split[i]);
                if (i < split.length - 2) {
                    fileNamePix.append(".");
                }
            }
        } else {
            fileNamePix.append(fileName);
        }
        return fileNamePix.toString();
    }
}
